home *** CD-ROM | disk | FTP | other *** search
/ Power CD / Power CD ATARI-Rechner Lieben.iso / UTILITY / LSRC_222 / DECODE5.S next >
Encoding:
Text File  |  1993-07-28  |  17.9 KB  |  1,101 lines

  1.  
  2.             export        bitbuf
  3.             export        bitcount
  4.             export        subbitbuf
  5.             export        origsize
  6.             export        bad_tab
  7.  
  8.             export        fillbuf
  9.             export        getbits
  10.             export        decode_lh5
  11.             export        decode5
  12.             export        send_block
  13.             export        make_table
  14.             export        putbits
  15.             export        compsize
  16.  
  17.             import        outrec
  18.             import        outfname
  19.             import        heap
  20.             import        heapsize
  21.             import        freq
  22.             import        infile
  23.             import        outfile
  24.             import        right
  25.             import        left
  26.             import        dad
  27.             import        blocksize
  28.             import        pt_table
  29.             import        pt_len
  30.             import        c_len
  31.             import        crc
  32.             import        text_buf
  33.             import        flg_q
  34.             import        has_crc
  35.             import        ProcInd
  36.             import        StdOut
  37.             import        errorlevel
  38.             import        c_code
  39.             import        c_freq
  40.             import        pt_code
  41.             import        p_freq
  42.             import        t_freq
  43.             import        M_BADTAB
  44.  
  45.             import        block_crc
  46.             import        read_c_len
  47.             import        read_pt_len
  48.             import        make_tree
  49.             import        count_t_freq
  50.             import        write_pt_len
  51.             import        write_c_len
  52.             import        _filbuf
  53.             import        fwrite
  54.             import        error
  55.             import        shipout
  56.             import        puts
  57.  
  58. NC            equ            510
  59. NT            equ            19
  60. NP            equ            14
  61.  
  62. WTERR        equ         14
  63.  
  64.  
  65. fillbuf:    move.w        d4,-(sp)
  66.             pea            (a2)
  67.  
  68.             move.w        d0,d1
  69.             lea.l        bitbuf(pc),a2
  70.  
  71.             move.w        (a2)+,d2
  72.             move.w        (a2)+,d0
  73.             move.w        (a2)+,d4
  74.  
  75.             lsl.w        d1,d2
  76.  
  77.             cmp.w        d1,d4
  78.             bge.s        fbuf_exitf
  79.  
  80.             move.l        infile(pc),a0
  81.             movea.l     4(a0),a1
  82.  
  83. fbuf_whilef:sub.w        d4,d1
  84.             moveq.l     #8,d4
  85.  
  86.             lsl.w        d1,d0
  87.             or.w        d0,d2
  88.  
  89.             moveq.l     #0,d0
  90.  
  91.             subq.l        #1,(a2)
  92.             bmi.s        fbuf_wendf
  93.  
  94.             subq.l        #1,(a0)
  95.             bmi.s        fbuf_fgetcf
  96.  
  97.             move.b        (a1)+,d0
  98.  
  99. fbuf_wendf: cmp.w        d1,d4
  100.             blt.s        fbuf_whilef
  101.  
  102.             move.l        a1,4(a0)
  103.  
  104. fbuf_exitf: sub.w        d1,d4
  105.             move.w        d0,d1
  106.             lsr.w        d4,d0
  107.             or.w        d2,d0
  108.  
  109.             movem.w     d0/d1/d4,-(a2)
  110.             move.l         (sp)+,a2
  111.             move.w        (sp)+,d4
  112.             rts
  113.  
  114.  
  115. fbuf_fgetcf:move.l        a1,4(a0)
  116.             movem.l     d1-d2/a0,-(sp)
  117.             bsr         _filbuf
  118.             movem.l     (sp)+,d1-d2/a0
  119.             move.l        4(a0),a1
  120.             bra.s        fbuf_wendf
  121.  
  122. fbuf_fgetcg:move.l        a1,4(a0)
  123.             movem.l     d1-d2/a0,-(sp)
  124.             bsr         _filbuf
  125.             movem.l     (sp)+,d1-d2/a0
  126.             move.l        4(a0),a1
  127.             bra.s        fbuf_wendg
  128.  
  129.  
  130. getbits:    move.w        d4,-(sp)
  131.             pea            (a2)
  132.  
  133.             lea.l        bitbuf(pc),a2
  134.             move.w        d0,d1
  135.  
  136.             move.w        (a2),d2
  137.             moveq.l     #16,d0
  138.             sub.w        d1,d0
  139.             lsr.w        d0,d2
  140.  
  141.             swap        d2
  142.             move.w        (a2)+,d2
  143.             move.w        (a2)+,d0
  144.             move.w        (a2)+,d4
  145.  
  146.             lsl.w        d1,d2
  147.  
  148.             cmp.w        d1,d4
  149.             bge.s        fbuf_exitg
  150.  
  151.             movea.l     infile(pc),a0
  152.             movea.l     4(a0),a1
  153.  
  154. fbuf_whileg:sub.w        d4,d1
  155.             moveq.l     #8,d4
  156.  
  157.             lsl.w        d1,d0
  158.             or.w        d0,d2
  159.  
  160.             moveq.l     #0,d0
  161.  
  162.             subq.l        #1,(a2)
  163.             bmi.s        fbuf_wendg
  164.  
  165.             subq.l        #1,(a0)
  166.             bmi.s        fbuf_fgetcg
  167.  
  168.             move.b        (a1)+,d0
  169.  
  170. fbuf_wendg: cmp.w        d1,d4
  171.             blt.s        fbuf_whileg
  172.  
  173.             move.l        a1,4(a0)
  174.  
  175. fbuf_exitg: sub.w        d1,d4
  176.             move.w        d0,d1
  177.             lsr.w        d4,d0
  178.             or.w        d2,d0
  179.  
  180.             movem.w     d0/d1/d4,-(a2)
  181.             move.l        (sp)+,a2
  182.             move.w        (sp)+,d4
  183.  
  184.             swap        d2
  185.             move.w        d2,d0
  186.  
  187.             rts
  188.  
  189.  
  190. make_table: movem.l     D3-D7/A2-A6,-(SP)
  191.             lea         -$78(SP),SP
  192.  
  193.             move.w        D0,$76(SP)    ; nchar
  194.             move.w        D1,D6        ; tablebits
  195.             move.l        A0,$72(SP)    ; bitlen
  196.             move.l        A1,A6        ; table
  197.             lea.l        left(PC),A3
  198.             lea.l        $2+2(SP),A4 ; &start[1]
  199.             lea         $4C(SP),A5    ; count
  200.  
  201.             lea.l        2(A5),A1    ; &count[1]
  202.             moveq.l     #0,D1
  203.             rept        8
  204.             move.l        D1,(A1)+
  205.             endm
  206.  
  207.             subq.w        #1,D0
  208.             bmi.s        no_init
  209.  
  210. init_count: moveq.l     #0,D1
  211.             move.b        (A0)+,D1
  212.             add.w        D1,D1
  213.             addq.w        #1,0(A5,D1.W)
  214.             dbra        d0,init_count
  215.  
  216. no_init:    move.l        A4,A0        ; &start[1]
  217.             lea.l        2(A5),A1    ; &count[1]
  218.             moveq.l     #0,d5        ; k=0
  219.             move.w        D5,(A0)+    ; start[1]=0
  220.             moveq.l     #15,D2
  221.  
  222. init_start:    REPT        4
  223.             move.w        (a1)+,D1
  224.             lsl.w        D2,D1
  225.             add.w        D1,D5
  226.             move.w        D5,(A0)+
  227.             subq.w        #1,d2
  228.             ENDM
  229.             bpl.s        init_start
  230.  
  231.             tst.w        D5            ; k==0
  232.             beq.s        table_ok
  233.  
  234.             ori.w        #1,errorlevel
  235.             addq.w        #1,bad_tab
  236.             tst.b        flg_q
  237.             bne.s        _bad_table
  238.  
  239.             lea         M_BADTAB(pc),A0
  240.             bsr         puts
  241.  
  242. _bad_table: moveq.l     #0,d0
  243.             bra         make_exit
  244.  
  245. table_ok:    moveq.l     #16,D2
  246.             sub.w        D6,D2
  247.             move.w        D2,(SP) ; jutbits
  248.  
  249.             moveq.l     #1,D3
  250.             lea.l        $26+2(SP),A0; &weight[1]
  251.  
  252.             move.w        D6,D7
  253.             subq.w        #1,D7
  254.             bmi.s        no_start_weight
  255.  
  256.             move.l        A4,A1    ; &start[1]
  257.             add.w        D6,D3
  258.  
  259. start_weight:
  260.             move.w        (A1),D0     ; start[i] >>= jutbits
  261.             lsr.w        D2,D0
  262.             move.w        D0,(A1)+
  263.  
  264.             moveq.l     #1,D1
  265.             lsl.w        D7,D1
  266.             move.w        D1,(A0)+
  267.  
  268.             dbra        D7,start_weight
  269.  
  270. no_start_weight:
  271.             moveq.l     #16,D1
  272.             sub.w        D3,D1
  273.             bmi.s        no_while_weight
  274.  
  275.             moveq.l     #0,D0
  276.             bset        D1,D0
  277. while_weight:
  278.             move.w        D0,(A0)+
  279.             lsr.l        D0
  280.             dbra        D1,while_weight
  281.  
  282. no_while_weight:
  283.             move.w        D6,D0
  284.             add.w        D0,D0
  285.             move.w        0(A4,D0.w),D3
  286.             lsr.w        D2,D3
  287.             beq.s        i_equal
  288.  
  289.             moveq.l     #1,D5
  290.             lsl.w        D6,D5
  291.  
  292.             cmp.w        D3,D5
  293.             beq.s        i_equal
  294.  
  295.             moveq.l     #0,D0
  296.             movea.l     A6,A1    ; table
  297.             add.w        D3,A1
  298.             add.w        D3,A1
  299.  
  300.             sub.w        D5,D3
  301.             not.w        D3
  302.  
  303. while_i:    move.w        D0,(A1)+
  304.             dbra        D3,while_i
  305.  
  306. i_equal:    moveq.l     #1,D1
  307.             moveq.l     #15,D2
  308.             sub.w        D6,D2
  309.             lsl.w        D2,D1
  310.             move.w        D1,$4A(SP)        ; mask
  311.  
  312.             move.w        $76(SP),D1        ; avail=nchar
  313.             lea         $26(SP),A0        ; weight
  314.             movea.l     $72(SP),A1        ; bitlen
  315.             lea         right(PC),A5
  316.  
  317.             moveq.l     #0,d0            ; ch
  318.             bra         ch_wend
  319.  
  320. while_ch:    moveq.l     #0,D4
  321.             move.b        (A1)+,D4    ; len=bitlen[ch]
  322.             beq.b        next_ch
  323.  
  324.             move.w        D4,D7
  325.             add.w        D7,D7
  326.             move.w        -2(A4,D7.w),D2
  327.             move.w        D2,D5            ; k=start[len]
  328.             add.w        0(A0,D7.w),D2
  329.             move.w        D2,$48(SP)        ; nextcode
  330.             movea.l     A6,A2            ; table
  331.  
  332.             cmp.w        D6,D4            ; len<=tablebits
  333.             bgt.s        len_gt_tablebits
  334.  
  335.             cmp.w        D2,D5
  336.             bge.s        endif
  337.  
  338.             adda.w        D5,A2
  339.             adda.w        D5,A2
  340.  
  341.             sub.w        D5,D2
  342.             subq.w        #1,D2
  343.  
  344. for_i:        move.w        D0,(A2)+
  345.             dbra        D2,for_i
  346.             bra.s        endif
  347.  
  348. len_gt_tablebits:
  349.             move.w        (SP),D2 ; jutbits
  350.             move.w        D5,D7
  351.             lsr.w        D2,D7
  352.             add.w        D7,D7
  353.             adda.w        D7,A2
  354.  
  355.             move.w        D4,D3
  356.             sub.w        D6,D3
  357.             subq.w        #1,d3
  358.             bmi.s        i_endif
  359.  
  360. while_i_else:
  361.             move.w        (A2),D7
  362.             add.w        D7,D7
  363.             bne.s        table_ne
  364.  
  365.             moveq.l     #0,D2
  366.             move.w        D1,D7
  367.             add.w        D7,D7
  368.             move.w        D2,(A3,D7.W)
  369.             move.w        D2,(A5,D7.W)
  370.             move.w        D1,(A2)
  371.             addq.w        #1,D1
  372.  
  373. table_ne:    move.w        D5,D2
  374.             and.w        $4A(SP),D2
  375.             beq.s        no_mask
  376.  
  377.             lea         0(A5,D7.w),A2
  378.             bra.s        mask
  379.  
  380. no_mask:    lea         0(A3,D7.w),A2
  381. mask:        add.w        D5,D5
  382.  
  383.             dbra        d3,while_i_else
  384. i_endif:    move.w        D0,(A2)
  385.  
  386. endif:        add.w        D4,D4
  387.             move.w        $48(SP),-2(A4,D4.w) ; start[len]=nextcode
  388.  
  389. next_ch:    addq.w        #1,D0
  390. ch_wend:    cmp.w        $76(SP),D0    ; ch<nchar
  391.             blt         while_ch
  392.  
  393. make_ok:    moveq.l     #-1,D0
  394.  
  395. make_exit:    lea         $78(SP),SP
  396.             movem.l     (SP)+,D3-D7/A2-A6
  397.             rts
  398.  
  399.  
  400. decode_lh5: movem.l     D3-D7/A2-A6,-(SP)
  401.  
  402.             move.w        #$FF,d4     ; m
  403.             lea.l        dec_j(pc),a2
  404.  
  405.             moveq.l     #0,d6
  406.             moveq.l     #8,d7
  407.             move.w        d6,crc
  408.             move.w        d6,bsize-dec_j(a2)
  409.  
  410.             move.l        d6,(a2)+
  411.             move.l        d6,(a2)+
  412.             move.l        D1,(a2)+    ; pacsize
  413.             move.l        D0,(a2)     ; origsize
  414.  
  415.             moveq.l     #16,D0
  416.             bsr         fillbuf
  417.  
  418.             move.l        outfile(pc),d5
  419.             lea         text_buf,A4
  420.  
  421.             moveq.l     #0,d3
  422.             bra         wend_orig
  423.  
  424. while_orig: move.w        #$2000,d3    ; n
  425.             cmp.l        d3,d0
  426.             bhs.s        dic_size
  427.  
  428.             move.w        d0,d3
  429.  
  430. dic_size:    bsr         decode5
  431.             tst.w        d0
  432.             beq.s        bad_table
  433.  
  434.             tst.l        d5
  435.             beq.s        no_error
  436.  
  437.             move.l        d3,d1
  438.             movea.l     d5,a1
  439.             movea.l     a4,a0
  440.             moveq.l     #1,d0
  441.             bsr         fwrite
  442.  
  443.             cmp.l        d3,d0
  444.             bcc.s        no_error
  445.  
  446.             sub.l        a0,a0
  447.             moveq.l     #WTERR,d0
  448.             moveq.l        #-1,D1
  449.             jmp         error
  450.  
  451. no_error:    sub.l        d3,(a2)
  452.             add.l        d3,d6
  453.  
  454.             tst.b        has_crc
  455.             beq.s        no_crc
  456.  
  457.             move.l        a4,a0
  458.             move.l        d3,d0
  459.             bsr            block_crc
  460.  
  461. no_crc:     tst.l        (a2)
  462.             beq.s        ind
  463.  
  464. proc_ind:    cmp.l        blocksize(pc),d6
  465.             blt.s        wend_orig
  466.  
  467. ind:        sub.l        blocksize(pc),d6
  468.  
  469.             cmp.l        StdOut(PC),d5
  470.             beq.s        proc_ind
  471.  
  472.             bsr         ProcInd
  473.             bra.s        proc_ind
  474.  
  475. wend_orig:    move.l        (a2),d0
  476.             bne         while_orig
  477.  
  478.             moveq.l     #1,d0
  479.  
  480. bad_table:    movem.l     (SP)+,D3-D7/A2-A6
  481.             rts
  482.  
  483. ; *****
  484.  
  485. fbuf_fgetc:    move.l        infile(pc),a0
  486.             move.l        d7,(a0)
  487.             move.l        a6,4(a0)
  488.             movem.l        d1/d2/a0/a1,-(sp)
  489.             bsr         _filbuf
  490.             movem.l        (sp)+,d1/d2/a0/a1
  491.             move.l        (a0),d7
  492.             move.l        4(a0),a6
  493.             rts
  494.  
  495. decode5:    movem.l     d3-d7/a2/a4,-(sp)
  496.  
  497.             subq.w        #1,d3                ; count
  498.  
  499.             move.w        bsize(pc),d6
  500.             swap        d6
  501.             move.w        dec_j(pc),d6
  502.  
  503.             move.l         infile(pc),a0
  504.             move.l        (a0),d7
  505.             move.l        4(a0),a6
  506.  
  507.             lea         left(PC),a1
  508.             lea.l         bitbuf(pc),a2
  509.             move.l        dad(pc),a3
  510.             movea.l        a4,a5                ; text_buf
  511.  
  512.             move.w        (a2)+,d2
  513.             move.w        i(pc),d4
  514.  
  515.             subq.w        #1,d6
  516.             bmi.s        for
  517.  
  518.             move.w        #$1fff,d5            ; DICSIZ - 1
  519.  
  520. while_loop1:move.b        (a4,d4.w),(a5)+
  521.             addq.w        #1,d4
  522.             and.w        d5,d4
  523.             subq.w        #1,d3
  524.             dbmi        d6,while_loop1
  525.             bpl.s        for
  526.             bra            dc_return
  527.  
  528. for:        swap        d6
  529.             dbra        d6,dont_read_bsize
  530.  
  531.             move.w        d2,d6
  532.             subq.w        #1,d6
  533.  
  534.             move.w        (a2)+,d0
  535.             move.w        (a2)+,d5
  536.  
  537.             moveq.l     #16,d1
  538.             moveq.l        #0,d2
  539.  
  540.             cmp.w        d1,d5
  541.             blt.s        fbuf_while1
  542.             bra.s        fbuf_exit1
  543.  
  544. fbuf_fgetc1:bsr            fbuf_fgetc
  545.             bra.s        fbuf_wend1
  546.  
  547. fbuf_while1:sub.w        d5,d1
  548.             moveq.l     #8,d5
  549.  
  550.             lsl.w        d1,d0
  551.             or.w        d0,d2
  552.  
  553.             moveq.l     #0,d0
  554.  
  555.             subq.l        #1,d7
  556.             bmi.s        fbuf_fgetc1
  557.  
  558.             move.b        (a6)+,d0
  559.  
  560. fbuf_wend1: cmp.w        d1,d5
  561.             blt.s        fbuf_while1
  562.  
  563. fbuf_exit1: sub.w        d1,d5
  564.             move.w        d0,d1
  565.             lsr.w        d5,d0
  566.             or.w        d2,d0
  567.  
  568.             movem.w     d0/d1/d5,-(a2)
  569.  
  570.             pea            (a1)
  571.  
  572.             move.l        infile(pc),a0
  573.             move.l        d7,(a0)
  574.             move.l        a6,4(a0)
  575.  
  576.             moveq.l     #19,d0
  577.             moveq.l     #5,d1
  578.             moveq.l     #3,d2
  579.             jsr         read_pt_len
  580.             tst.w        d0
  581.             beq         dc_err
  582.  
  583.             jsr         read_c_len
  584.             tst.w        d0
  585.             beq         dc_err
  586.  
  587.             moveq.l     #14,d0
  588.             moveq.l     #4,d1
  589.             moveq.l     #-1,d2
  590.             jsr         read_pt_len
  591.             tst.w        d0
  592.             beq         dc_err
  593.  
  594.             move.l        infile(pc),a0
  595.             move.l        (a0),d7
  596.             move.l        4(a0),a6
  597.             move.w        (a2)+,d2
  598.  
  599.             move.l        (sp)+,a1
  600.  
  601. dont_read_bsize:
  602.             swap        d6
  603.             move.w        d2,d1
  604.             lsr.w        #4,d1
  605.             add.w        d1,d1
  606.             swap        d3
  607.             move.w        0(a3,d1.w),d3
  608.  
  609.             cmp.w        #510,d3
  610.             bcs.s        no_do1
  611.  
  612.             moveq.l     #3,d1
  613.             move.w        #510,d0
  614.             lea.l        right(pc),a0
  615.  
  616. do1:        add.w        d3,d3
  617.             btst        d1,d2
  618.             beq.s        do_else1
  619.  
  620.             move.w        0(a0,d3.w),d3
  621.  
  622.             cmp.w        d0,d3
  623.             dblt        d1,do1
  624.             bra.s        no_do1
  625.  
  626. do_else1:    move.w        0(a1,d3.w),d3
  627.  
  628.             cmp.w        d0,d3
  629.             dblt        d1,do1
  630.  
  631. no_do1:     lea.l        c_len(pc),a0
  632.             moveq.l     #0,d1
  633.             move.b        0(a0,d3.w),d1
  634.  
  635.             move.w        (a2)+,d0
  636.             move.w        (a2)+,d5
  637.  
  638.             lsl.w        d1,d2
  639.  
  640.             cmp.w        d1,d5
  641.             bge.s        fbuf_exit2
  642.  
  643. fbuf_while2:sub.w        d5,d1
  644.             moveq.l     #8,d5
  645.  
  646.             lsl.w        d1,d0
  647.             or.w        d0,d2
  648.  
  649.             moveq.l     #0,d0
  650.  
  651.             subq.l        #1,d7
  652.             bmi.s        fbuf_fgetc2
  653.  
  654.             move.b        (a6)+,d0
  655.  
  656. fbuf_wend2: cmp.w        d1,d5
  657.             blt.s        fbuf_while2
  658.  
  659. fbuf_exit2: sub.w        d1,d5
  660.             move.w        d5,-(a2)
  661.             move.w        d0,-(a2)
  662.  
  663.             lsr.w        d5,d0
  664.             or.w        d0,d2
  665.  
  666.             cmpi.w        #255,d3
  667.             bhi.s        c_gt_ucmax
  668.  
  669.             move.b        d3,(a5)+
  670.             swap        d3
  671.             dbra        d3,for
  672.             bra            dc_return
  673.  
  674. fbuf_fgetc2:bsr            fbuf_fgetc
  675.             bra.s        fbuf_wend2
  676.  
  677. c_gt_ucmax: move.w        d3,d6
  678.             subi.w        #253,d6
  679.             swap        d3
  680.  
  681.             move.w        d2,d1        ; count
  682.             lsr.w        #8,d1
  683.             add.w        d1,d1
  684.             lea.l        pt_table(pc),a0
  685.             move.w        0(a0,d1.w),d4
  686.  
  687.             moveq.l     #14,d0
  688.             cmp.w        d0,d4
  689.             bcs.s        no_do2
  690.  
  691.             moveq.l     #7,d1
  692.             lea.l        right(pc),a0
  693.  
  694. do2:        add.w        d4,d4
  695.             btst        d1,d2
  696.             beq.s        do_else2
  697.  
  698.             move.w        0(a0,d4.w),d4
  699.  
  700.             cmp.w        d0,d4
  701.             dblt        d1,do2
  702.             bra.s        no_do2
  703.  
  704. fbuf_fgetc3:bsr            fbuf_fgetc
  705.             bra.s        fbuf_wend3
  706.  
  707. do_else2:    move.w        0(a1,d4.w),d4
  708.  
  709.             cmp.w        d0,d4
  710.             dblt        d1,do2
  711.  
  712. no_do2:        lea         pt_len(pc),a0
  713.             moveq.l     #0,d1
  714.             move.b        0(a0,d4.w),d1
  715.  
  716.             move.w        (a2)+,d0
  717.             move.w        (a2)+,d5
  718.  
  719.             lsl.w        d1,d2
  720.  
  721.             cmp.w        d1,d5
  722.             bge.s        fbuf_exit3
  723.  
  724. fbuf_while3:sub.w        d5,d1
  725.             moveq.l     #8,d5
  726.  
  727.             lsl.w        d1,d0
  728.             or.w        d0,d2
  729.  
  730.             moveq.l     #0,d0
  731.  
  732.             subq.l        #1,d7
  733.             bmi.s        fbuf_fgetc3
  734.  
  735.             move.b        (a6)+,d0
  736.  
  737. fbuf_wend3: cmp.w        d1,d5
  738.             blt.s        fbuf_while3
  739.  
  740. fbuf_exit3: sub.w        d1,d5
  741.  
  742.             subq.w        #1,d4
  743.             bmi.s        i_minus
  744.  
  745.             move.w        d0,d1
  746.             lsr.w        d5,d1
  747.             or.w        d1,d2
  748.  
  749.             move.w        d2,a0
  750.             moveq.l     #16,d1
  751.             sub.w        d4,d1
  752.             lsr.w        d1,d2
  753.             exg            d2,a0
  754.  
  755.             move.w        d4,d1
  756.             lsl.w        d1,d2
  757.  
  758.             cmp.w        d1,d5
  759.             bge.s        fbuf_exit4
  760.  
  761. fbuf_while4:sub.w        d5,d1
  762.             moveq.l     #8,d5
  763.  
  764.             lsl.w        d1,d0
  765.             or.w        d0,d2
  766.  
  767.             moveq.l     #0,d0
  768.  
  769.             subq.l        #1,d7
  770.             bmi.s        fbuf_fgetc4
  771.  
  772.             move.b        (a6)+,d0
  773.  
  774. fbuf_wend4: cmp.w        d1,d5
  775.             blt.s        fbuf_while4
  776.  
  777. fbuf_exit4: sub.w        d1,d5
  778.             move.w        d5,-(a2)
  779.             move.w        d0,-(a2)
  780.  
  781.             lsr.w        d5,d0
  782.             or.w        d0,d2
  783.  
  784.             moveq.l     #0,d0
  785.             bset        d4,d0
  786.             move.l        a5,d4
  787.             sub.l        a4,d4
  788.             sub.w        d0,d4
  789.             sub.w        a0,d4
  790.             subq.w        #1,d4
  791.             move.w        #$1fff,d5    ; DICSIZ - 1
  792.             and.w        d5,d4
  793.             dbra        d6,while_loop2
  794.             bra            for
  795.  
  796. fbuf_fgetc4:pea            (a0)
  797.             bsr            fbuf_fgetc
  798.             move.l        (sp)+,a0
  799.             bra.s        fbuf_wend4
  800.  
  801. i_minus:    move.w        d5,-(a2)
  802.             move.w        d0,-(a2)
  803.  
  804.             lsr.w        d5,d0
  805.             or.w        d0,d2
  806.  
  807.             add.l        a5,d4
  808.             sub.l        a4,d4
  809.             move.w        #$1fff,d5    ; DICSIZ - 1
  810.             and.w        d5,d4
  811.             dbra        d6,while_loop2
  812.             bra         for
  813.  
  814. while_loop2:move.b        (a4,d4.w),(a5)+
  815.             addq.w        #1,d4
  816.             and.w        d5,d4
  817.             subq.w        #1,d3
  818.             dbmi        d6,while_loop2
  819.             bpl            for
  820.  
  821. dc_return:    moveq.l     #1,d0
  822.  
  823.             move.w        d2,-(a2)
  824.             move.w        d4,i-bitbuf(a2)
  825.             move.w        d6,dec_j-bitbuf(a2)
  826.             swap        d6
  827.             move.w        d6,bsize-bitbuf(a2)
  828.  
  829.             move.l        infile(pc),a0
  830.             move.l        d7,(a0)
  831.             move.l        a6,4(a0)
  832.  
  833.             movem.l     (sp)+,d3-d7/a2/a4
  834.             rts
  835.  
  836. dc_err:        moveq.l        #0,d0
  837.             addq.l        #4,sp
  838.             movem.l     (sp)+,d3-d7/a2/a4
  839.             rts
  840.  
  841.  
  842. putbits:    lea.l        bitcount(pc),a1
  843.             sub.w        (a1),d0
  844.             bge.b        _n_ge_bitcount
  845.  
  846.             neg.w        d0
  847.             move.w        d0,(a1)
  848.             lsl.w        d0,d1
  849.             or.w        d1,-(a1)
  850.             rts
  851.  
  852. _n_ge_bitcount:
  853.             move.w        d1,d2
  854.             lsr.w        d0,d2
  855.             or.w        -(a1),d2
  856.  
  857.             lea         outrec(pc),a0
  858.             move.l        (a0),a1
  859.             move.b        d2,(a1)+
  860.  
  861.             subq.w        #8,d0
  862.             bge.b        _n_ge_charbit
  863.  
  864.             move.l        a1,(a0)+
  865.  
  866.             lea.l        compsize(pc),a1
  867.             addq.l        #1,(a1)
  868.  
  869.             neg.w        d0
  870.             lsl.w        d0,d1
  871.             move.w        d0,-(a1)
  872.             move.w        d1,-(a1)
  873.  
  874.             subq.l        #1,(a0)
  875.             bpl.b        _no_ship
  876.             bmi         shipout
  877.  
  878. _n_ge_charbit:
  879.             move.w        d1,d2
  880.             lsr.w        d0,d2
  881.  
  882.             move.b        d2,(a1)+
  883.             move.l        a1,(a0)+
  884.  
  885.             lea.l        compsize(pc),a1
  886.             addq.l        #2,(a1)
  887.  
  888.             neg.w        d0
  889.             addq.w        #8,d0
  890.             lsl.w        d0,d1
  891.             move.w        d0,-(a1)
  892.             move.w        d1,-(a1)
  893.  
  894.             subq.l        #2,(a0)
  895.             bpl.b        _no_ship
  896.  
  897.             bra         shipout
  898.  
  899. _no_ship:    rts
  900.  
  901.  
  902. send_block:    movem.l        D3-D7/A2-A6,-(SP)
  903.  
  904.             lea            c_freq(pc),A2
  905.             lea            text_buf,A3
  906.             lea            c_code(pc),A4
  907.             lea            c_len(pc),A5
  908.             lea               pt_code(pc),A6
  909.  
  910.             pea            (A4)
  911.             movea.l        A5,A1
  912.             movea.l     A2,A0
  913.             move.w      #NC,D0
  914.             bsr               make_tree    ; make_tree(NC,freq,c_len,c_code)
  915.             addq.w        #4,SP
  916.  
  917.             move.w        D0,D3            ; k
  918.  
  919.             add.w       D0,D0
  920.             move.w      0(A2,D0.w),D4    ; size=c_freq[k]
  921.  
  922.             move.w      D4,D1
  923.             moveq.l     #16,D0
  924.             bsr            putbits            ; putbits(16,size)
  925.  
  926.             cmp.w       #NC,D3            ; k>=NC ?
  927.             bcs.s       k_lt_NC
  928.  
  929.             jsr               count_t_freq
  930.  
  931.             pea               (A6)
  932.             lea               pt_len(pc),A1
  933.             lea               t_freq(pc),A0
  934.             moveq.l     #NT,D0
  935.             bsr            make_tree        ; make_tree(NT,t_freq,pt_len,pt_code)
  936.             addq.w        #4,SP
  937.  
  938.             move.w        D0,D3            ; k
  939.  
  940.             cmp.w        #NT,D3            ; k>=NT ?
  941.             bcs.s        k_lt_NT
  942.  
  943.             moveq.l        #3,D2
  944.             moveq.l        #5,D1
  945.             moveq.l        #NT,D0
  946.             jsr            write_pt_len    ; write_pt_len(NT,TBIT,3)
  947.             jsr               write_c_len
  948.             bra.s        _k_ge_NC
  949.  
  950. k_lt_NT:     moveq.l        #0,D1
  951.             moveq.l     #5,D0
  952.             bsr         putbits
  953.  
  954.             move.w        D3,D1
  955.             moveq.l     #5,D0
  956.             bsr         putbits
  957.  
  958.             jsr               write_c_len
  959.             bra.s        _k_ge_NC
  960.  
  961. k_lt_NC:    moveq.l        #0,D1
  962.             moveq.l        #8,D0
  963.             bsr         putbits
  964.  
  965.             moveq.l        #0,D1
  966.             moveq.l        #11,D0
  967.             bsr            putbits
  968.  
  969.             move.w        D3,D1
  970.             moveq.l     #9,D0
  971.             bsr            putbits
  972.  
  973. _k_ge_NC:    pea            (A6)
  974.             lea            pt_len(pc),A1
  975.             lea         p_freq(pc),A0
  976.             moveq.l     #NP,D0
  977.             bsr         make_tree        ; make_tree(NP,p_freq,pt_len,pt_code)
  978.             addq.w        #4,SP
  979.  
  980.             move.w        D0,D3            ; k
  981.  
  982.             cmp.w        #NP,D3            ; k>=NP ?
  983.             bcs.s        k_lt_NP
  984.  
  985.             moveq.l        #-1,D2
  986.             moveq.l        #4,D1
  987.             moveq.l        #NP,D0
  988.             jsr         write_pt_len    ; write_pt_len(NP,PBIT,-1)
  989.             bra.s        _k_ge_NP
  990.  
  991. k_lt_NP:     moveq.l        #0,D1
  992.             moveq.l        #4,D0
  993.             bsr            putbits
  994.  
  995.             move.w        D3,D1
  996.             moveq.l        #4,D0
  997.             bsr            putbits
  998.  
  999. _k_ge_NP:    moveq.l        #0,d5        ; i
  1000.             lea.l        putbits(PC),a2
  1001.  
  1002. i_while:    add.w        D6,D6        ; flags
  1003.  
  1004.             moveq.l        #7,d0
  1005.             and.w        d5,d0
  1006.             bne.s        i_char_bit
  1007.  
  1008.             moveq.l        #0,d6
  1009.             move.b        (A3)+,D6    ; flags=*text_buf++
  1010.  
  1011. i_char_bit:    btst        #7,D6        ; flags&(1U<<(CHAR_BIT-1)) ?
  1012.             beq.s        _not_flags
  1013.  
  1014.             move.w        #256,D1
  1015.             or.b        (A3)+,D1        ; k=(*text_buf++)+(1U<<CHAR_BIT)
  1016.  
  1017.             moveq.l        #0,d0
  1018.             move.b        0(A5,D1.w),D0    ; c_len[k]
  1019.             add.w        D1,D1
  1020.             move.w        0(A4,D1.w),D1    ; c_code[k]
  1021.             jsr            (a2)            ; putbits
  1022.  
  1023.             moveq.l        #0,D7            ; c
  1024.             move.b        (A3)+,D3        ; k=(*text_buf++)<<CHAR_BIT
  1025.             lsl.w        #8,D3
  1026.             move.b        (A3)+,D3         ; k|=*text_buf++
  1027.             move.w        D3,D0
  1028.             beq.s        no_q
  1029.  
  1030. while_q:    addq.w        #1,D7            ; c++
  1031.             lsr.w        #1,D0            ; q>>=1
  1032.             bne.s        while_q
  1033.  
  1034. no_q:        move.w        D7,D0
  1035.             add.w        D0,D0
  1036.             move.w        0(A6,D0.w),D1    ; pt_code[c]
  1037.  
  1038.             moveq.l        #0,D0
  1039.             lea            pt_len(PC),A0
  1040.             move.b        0(A0,D7.w),D0    ; pt_len[c]
  1041.             jsr         (a2)            ; putbits
  1042.  
  1043.             subq.w        #1,d7            ; c>1 ?
  1044.             bls.s        i_wend
  1045.  
  1046.             moveq.l        #-1,d1
  1047.             moveq.l        #16,d0
  1048.             sub.w        d7,d0
  1049.             lsr.w        d0,d1
  1050.             and.w        D3,D1            ; k&(0xFFFFU>>(17-c))
  1051.             move.w        d7,d0            ; c-1
  1052.             jsr         (a2)            ; putbits
  1053.  
  1054.             addq.w        #1,D5            ; i++
  1055.             cmp.w        D5,D4            ; i<size ?
  1056.             bhi.s        i_while
  1057.             bra.s        _send_exit
  1058.  
  1059. _not_flags:    moveq.l        #0,D1
  1060.             move.b        (A3)+,D1        ; k=*text_buf++
  1061.  
  1062.             moveq.l        #0,D0
  1063.             move.b        0(A5,D1.w),D0    ; c_len[k]
  1064.             add.w        D1,D1
  1065.             move.w        0(A4,D1.w),D1    ; c_code[k]
  1066.             jsr         (a2)            ; putbits
  1067.  
  1068. i_wend:        addq.w        #1,D5            ; i++
  1069.             cmp.w        D5,D4            ; i<size ?
  1070.             bhi            i_while
  1071.  
  1072. _send_exit:    move.w        #(NC>>2)-1,D5
  1073.             moveq.l        #0,D3
  1074.  
  1075.             lea            c_freq(pc),A2
  1076. c_freq_clr:    REPT        2
  1077.             move.l        D3,(A2)+
  1078.             ENDM
  1079.             dbra        D5,c_freq_clr
  1080.             move.l        D3,(A2)+
  1081.  
  1082.             lea         p_freq(PC),A2
  1083.             REPT        7
  1084.             move.l        D3,(A2)+
  1085.             ENDM
  1086.  
  1087.             movem.l        (SP)+,D3-D7/A2-A6
  1088.             rts
  1089.  
  1090. dec_j:        .DC.W    0
  1091. bitbuf:     .DC.W    0
  1092. subbitbuf:    .DC.W    0
  1093. bitcount:    .DC.W    0
  1094. compsize:    .DC.L    0
  1095. origsize:    .DC.L    0
  1096. i:            .DC.W    0
  1097. bsize:        .DC.W    0
  1098. bufptr:     .DC.L    0
  1099. bad_tab:    .DC.W    0
  1100.  
  1101.             .END